package top.carrotguo.weibo.ui.base;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.ProgressBar;
import android.widget.Toast;

import top.carrotguo.weibo.presenter.BasePresenter;
import top.carrotguo.weibo.view.IView;

/**
 * Created by carrot on 2018-10-10.
 */

public abstract class MVPBaseActivity<V extends IView, T extends BasePresenter<V>> extends BaseActivity {

    protected T mPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        mPresenter = createPresenter();
        if (null != mPresenter) {
            //绑定view到presenter
            mPresenter.attachView((V)this);
        }
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //解除绑定
        if (null != mPresenter) {
            mPresenter.detachView();
            mPresenter = null;
        }
    }

    public abstract T createPresenter();

}
